import array, heapq
import os, os.path
assert array.array('f').itemsize == 4
iters = []


def intsfromfile(f):
  while True:
     a = array.array('f')
     a.fromstring(f.read(4000))
     if not a:
         break
     for x in a:
         yield x



outputFileName = "/home/diaosi/outputDirForTermScores/allScores_sorted.binary"
outputFileHandler = open(outputFileName,"wb")

a = array.array('f')
for x in heapq.merge(*iters):
  a.append(x)
  if len(a) >= 1000:
      a.tofile(outputFileHandler)
      del a[:]
if a:
  a.tofile(outputFileHandler)
  


outputFileHandler.close()
print "done"